<?php

namespace App\Models\Order\Model;

use App\Models\Product\Model\Product;
use App\Models\User\Model\User;
use Illuminate\Database\Eloquent\Model;

class Cash extends Model
{
    //
    protected $guarded=[];
    protected $appends=['totals'];

    public function products()
    {
        return $this->hasMany(Product::class,'cash_id','id');
    }

    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    public function getTotalsAttribute()
    {
        return (Product::where([
            'cash_id'=>$this->id
        ])->sum('total'))??0;
    }
}
